package com.luoran.bartalks.action;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.luoran.bartalks.action.vo.PlanBizPicVo;
import com.luoran.bartalks.entity.biz.BtPlanBiz;
import com.luoran.bartalks.service.IBtPlanBizPicService;

/***
 * 强制拍照
 * 
 * @author wmm 2018年6月21日下午1:26:25
 * @version 1.0
 */
@Controller
@RequestMapping("/forcedPhoto")
public class BtForcedPhotoAction {

	@Autowired
	private IBtPlanBizPicService planBizPicService;

	private static final Logger log = LoggerFactory.getLogger(BtForcedPhotoAction.class);

	// 根据箱单物料关系id 获取强制拍照记录
	@RequestMapping("/list")
	@ResponseBody
	public JSONObject getForcedPhoto(String id) {// 箱单物料关系id.
		JSONObject result = new JSONObject();
		log.info("获取箱单物料关系id:[{}]的强制拍照记录", id);
		List<PlanBizPicVo> planBizPicVoList = new ArrayList<>();
		try {
			List<BtPlanBiz> forcedPhoto = planBizPicService.getPlanBiz(id);
			for (BtPlanBiz btPlanBiz : forcedPhoto) {
				PlanBizPicVo planBizPicVo = new PlanBizPicVo();
				planBizPicVo.setPositionName(btPlanBiz.getAddressName());
				planBizPicVo.setContainerName(btPlanBiz.getContainerName());
				planBizPicVo.setBizDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(btPlanBiz.getBizDate()));
				if (btPlanBiz.getBizType() == 10) {
					planBizPicVo.setBizType("装货");
				} else if (btPlanBiz.getBizType() == 20) {
					planBizPicVo.setBizType("卸货");
				} else {
					planBizPicVo.setBizType("未知");
				}
				planBizPicVo.setUserName(btPlanBiz.getUserName());
				List<String> list = planBizPicService.getPics(btPlanBiz.getId());
				if (list.size() == 0) {
					planBizPicVo.setPicList(null);
				} else {
					planBizPicVo.setPicList(list);
				}
				planBizPicVoList.add(planBizPicVo);
			}
			if (forcedPhoto.size() != 0) {
				result.put("flag", true);
				result.put("msg", planBizPicVoList);
				return result;
			} else {
				result.put("flag", false);
				result.put("msg", "未找到相应的记录!");
				return result;
			}
		} catch (Exception e) {
			e.printStackTrace();
			result.put("flag", false);
			result.put("msg", "系统异常");
			return result;
		}

	}
}
